<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        * {
            margin: 0;
            padding: 20px;
        }

        .ball {
            width: 40px;
            height: 40px;
            border-radius: 40px;
            margin-bottom: 10px;
            margin-left: 0;
        }

        .ball1 {
            background-color: #f60;
        }

        .ball2 {
            background-color: #0ae276;
        }

        .ball3 {
            background-color: #dd0c63;
        }
    </style>
</head>

<body>
    <div class="ball ball1" style="margin-left:0;"></div>
    <div class="ball ball2" style="margin-left:0;"></div>
    <div class="ball ball3" style="margin-left:0;"></div>

    <script>
        var ball1 = document.querySelector('.ball1');
        var ball2 = document.querySelector('.ball2');
        var ball3 = document.querySelector('.ball3');

        ballMove(ball1, 100, function () {
            return false;
        })



        function ballMove(ball, target, cb) {
            setTimeout(function () {
                var left = parseInt(ball.style.marginLeft, 10);
                console.log(left)
                if (left === target) {
                    cb && cb();

                } else {
                    if (left < target) {
                        left++;
                    } else {
                        left--;
                    }
                    ball.style.marginLeft = left + 'px';
                    ballMove(ball, target, cb);
                }
            }, 13);
        }
    </script>
</body>

</html>